<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>报价单</title>
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <link rel="stylesheet" href="${ctxStatic}/css/list.css">
	<c:set value="<%=ResourcesUtil.getConfig(\"inventory_status_all\")%>" var="inventoryStatusAll" />
	<c:set value="<%=ResourcesUtil.getConfig(\"inventory_category_purchase\")%>" var="inCategoryPurchase" />
    <script>
    $(document).ready(function(){
    	
    });
    
    function materialDetailList() {
    	var id="${materialOutInbound.id }";
    	var inventoryDetailId="${materialOutInbound.inventoryDetailId }";
    	var inventoryInOutKbn="${materialOutInbound.inventoryInOutKbn }";
    	params={"inventoryInOutKbn":inventoryInOutKbn,"id":id,"inventoryDetailId":inventoryDetailId};
    	$.post("${ctx}/material/inbound/materialDetailList",params,function(result){ 
        	$("#listHtml").html($(callBackHtml(result)).find("#listHtml").html());
    		tipParent(result.message);
        	saveQuantity();
        },'html');
	}
        
 	function saveQuantity() {
 		var inventoryDetailId = "${materialOutInbound.inventoryDetailId}";
 		var length = $("input.hiddenQuantity").length;
 		var result = parseFloat(0);
 		for (var i = 0; i < length; i++) {
 			var inventoryQuantity = $(".hiddenQuantity")[i].value;
 			if (inventoryQuantity==null||inventoryQuantity=="") {
 				inventoryQuantity = 0;
			}
 			inventoryQuantity = inventoryQuantity.replace(/,/g,"");
 			result += parseFloat(inventoryQuantity);
		}
 		var params = {"inventoryDetailId":inventoryDetailId,"inventoryQuantity":result}
 	    	$.post("${ctx}/material/inbound/saveQuantity",params,function(result){
 	    		/* 弹出提示框,关闭当前页面 */
 	    		tipParent(result.message);
 	    	},'json');
 	    	
	}
 
 	function inventoryBtn() {
 		var length = $("input.hiddenQuantity").length;
 		var result = parseFloat(0);
 		for (var i = 0; i < length; i++) {
 			var inventoryQuantity = $(".hiddenQuantity")[i].value;
 			if (inventoryQuantity==null||inventoryQuantity=="") {
 				inventoryQuantity = 0;
			}
 			inventoryQuantity = inventoryQuantity.replace(/,/g,"");
 			result += parseFloat(inventoryQuantity);
		}
 		
 		popup('500px','324px','${ctx}/material/inbound/detailCreate?materialCode=${materialOutInbound.materialCode}&materialNameCn=${materialOutInbound.materialNameCn}&requestQuantity=${materialOutInbound.requestQuantity}&id=${materialOutInbound.id}&inventoryDetailId=${materialOutInbound.inventoryDetailId}&inventoryInOutKbn=${materialOutInbound.inventoryInOutKbn }&inventoryCategory=${materialOutInbound.inventoryCategory }&materialId=${materialOutInbound.materialId}&realQuantity='+result);
	}
    <!--  -->
 	function closeThisWin() {
 		//获取 iframe 数量 
 		var frLength = window.parent.frames.length;
 		//父画面下标 
 		var parentIndex = frLength-2;
 		var inventoryCategory = "${materialOutInbound.inventoryCategory}";
 		var inCategoryPurchase = "${inCategoryPurchase}";
 		var inventoryStatus = "${materialOutInbound.inventoryStatus}";
 		var inventoryStatusAll = "${inventoryStatusAll}";
 		if (inventoryCategory == inCategoryPurchase && inventoryStatus != inventoryStatusAll) {
	 		var length = $("input.hiddenQuantity").length;
	 		var result = parseFloat(0);
	 		for (var i = 0; i < length; i++) {
	 			var inventoryQuantity = $(".hiddenQuantity")[i].value;
	 			if (inventoryQuantity==null||inventoryQuantity=="") {
	 				inventoryQuantity = 0;
				}
	 			inventoryQuantity = inventoryQuantity.replace(/,/g,"");
	 			result += parseFloat(inventoryQuantity);
			}
	 		var requestQuantity = "${materialOutInbound.requestQuantity}";
	 		if (result >= requestQuantity) {
	 			var venderId = $("#venderId").val();
	 			var materialId = $("#materialId").val();
	 			$.post("${ctx}/material/inbound/updateStatus?materialId="+materialId+"&venderId="+venderId,"",function(result){
	 				if (result == "true") {
		 	    		window.parent.frames[parentIndex].requestDetails();
		 	    		closeWin();
					}
	 	    	},'json');
			}else {
				window.parent.frames[parentIndex].requestDetails();
		 		closeWin();
			}
		}else{
			if (inventoryStatus != inventoryStatusAll) {
				saveQuantity();
			}
			window.parent.frames[parentIndex].requestDetails();
	 		closeWin();
		}
	}
    
    </script>
    <style type="text/css">
    		.tab-kcmxno{width: 50px;}
		    .tab-kcmxckmc{width: 175px;}
		    .tab-kcmxhjwz{width: 175px;}
		    .tab-kcmxkcsl{width: 175px;}
		    .tab-kcmxbz{width: 175px;}
    </style>
</head>
<body style="min-width: 770px">
<input type="hidden" id="venderId" value="${materialOutInbound.venderId }"/>
<input type="hidden" id="materialId" value="${materialOutInbound.materialId }"/>
<form id="searchForm">
<div class="layerHeader clearfix" style="width: 800px">
	<p class="headerTitle"><spring:message code="inventory_detail_inboundDetails"/></p>
	<div class="headerButton clearfix">
	<c:if test="${materialOutInbound.inventoryStatus!=inventoryStatusAll}">
		<c:if test="${materialOutInbound.requestQuantity != null && materialOutInbound.requestQuantity != '' }">
              <button type="button" onclick="inventoryBtn();"><spring:message code="inventory_detail_set_inventory" /></button>
          </c:if>
       </c:if>
       <button type="button" onclick="closeThisWin();"><spring:message code="inventory_detail_set_close" /></button>
     </div>
</div>
<div class="listArea" style="width: 800px">
                <div class="items clearfix" style="margin-left: 10px;">
                <div class="col-33 clearfix haveToBox">
                        <p class="tit"><spring:message code="inventory_detail_set_materialCode"/></p>
                        <label>${materialOutInbound.materialCode }</label>
                    </div>
                    <div class="col-33 clearfix haveToBox">
                   		<p class="tit"><spring:message code="inventory_detail_set_materialName"/></p>
                        <label>${materialOutInbound.materialNameCn }</label> 
                	</div>
            </div>
	<div style="height: 20px;padding: 0 10px;">
   		<p class="tit"><spring:message code="inventory_detail_set_inventoryDetail" /></p>
   	</div>
        <div class="tableArea tabBoxSm" >
            <div class="tableScroll tabSm" style="overflow: auto;height: 420px;width:770px">
                <table cellpadding="0" class="tableHead " >
                    <thead>
                    <tr>
                        <th><p class="tab-kcmxno"><spring:message code="common_no"/></p></th>
		                <th><p class="tab-kcmxckmc"><spring:message code="inventory_detail_set_warehouseName"/></p></th>
		                <th><p class="tab-kcmxhjwz"><spring:message code="inventory_detail_set_rackPlace"/></p></th>
		                <th><p class="tab-kcmxkcsl"><spring:message code="inventory_detail_set_inventoryQuantity"/></p></th>
		                <th><p class="tab-kcmxbz"><spring:message code="inventory_detail_set_remarks"/></p></th>
                    </tr>
                    </thead>
                </table>
                <table cellpadding="0" class="tableBody" >              
                    <tbody id = "listHtml">
                    <c:if test="${not empty materialOutInbound.requestDetailsList}">
            			<c:forEach items="${materialOutInbound.requestDetailsList}" var="requestDetailsInfo" varStatus="status">
            			<tr>
                			<td><p class="tab-kcmxno">${status.count}</p></td>
                			<td><p class="tab-kcmxckmc">${requestDetailsInfo.warehouseName}</p></td>
                			<td><p class="tab-kcmxhjwz">${requestDetailsInfo.rackPlace}</p></td>
                			<td><p class="tab-kcmxkcsl"><fmt:formatNumber value="${requestDetailsInfo.inventoryQuantity}" pattern="#,##0.###"/></p></td>
                			<td><p class="tab-kcmxbz">${requestDetailsInfo.remarks}</p></td>
                			<input type="hidden" class="hiddenQuantity" value="${requestDetailsInfo.inventoryQuantity}"/>
            			</tr>
            			</c:forEach>
            		</c:if>
                    </tbody>
                </table>
            </div>
            
    </div>
    <div id = "paging" ></div>
</div>
</form>
<script type="text/javascript">

</script> 
</body>
</html>
	